package com.finger.forest;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.finger.forest.base.BaseActivity;
import com.finger.forest.base.CommonKey;
import com.finger.forest.utils.ClickUtils;
import com.finger.forest.utils.Utils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 信息采集
 */
public class CollectionActivity extends BaseActivity implements View.OnClickListener {

    /**
     * 返回
     */
    @BindView(R.id.btn_back)
    ImageView backIv;

    /**
     * 道路采集
     */
    @BindView(R.id.tv_collection_road)
    TextView collectionRoadTv;

    /**
     * 道路采集列表
     */
    @BindView(R.id.tv_road_list)
    TextView roadListTv;

    /**
     * 火场采集
     */
    @BindView(R.id.tv_collection_fire)
    TextView collectionFireTv;

    /**
     * 火场采集列表
     */
    @BindView(R.id.tv_fire_list)
    TextView fireListTv;

    /**
     * 资源采集
     */
    @BindView(R.id.tv_collection_resource)
    TextView collectionResourceTv;

    /**
     * 资源采集列表
     */
    @BindView(R.id.tv_resource_list)
    TextView resourceListTv;

    private MapView mMapView;

    /**
     * 跳转列表类型 0：道路；1：火场；2：资源。
     */
    private int type = 0;

    @Override
    protected int setView() {
        return R.layout.activity_info_collection;
    }

    @Override
    protected void receiveData() {

    }

    @Override
    protected void initializeView() {
        mMapView = findViewById(R.id.mapView);
        setupMap();
    }

    @Override
    protected void loadDataFromServer() {

    }

    private void setupMap() {
        if (mMapView != null) {
            ArcGISRuntimeEnvironment.setLicense(CommonKey.LICENSE);
            mMapView.setAttributionTextVisible(false);
            Basemap.Type basemapType = Basemap.Type.IMAGERY;
            double latitude = 34.0270;
            double longitude = -118.8050;
            //int levelOfDetail = 13;
            int levelOfDetail = 14;
            ArcGISMap map = new ArcGISMap(basemapType, latitude, longitude, levelOfDetail);
            mMapView.setMap(map);
        }
    }

    @OnClick({R.id.btn_back, R.id.tv_collection_road, R.id.tv_collection_fire, R.id.tv_collection_resource,
            R.id.tv_road_list, R.id.tv_fire_list, R.id.tv_resource_list})
    @Override
    public void onClick(View v) {
        if (ClickUtils.isFastClick()) { //防止重复点击
            switch (v.getId()) {

                //返回
                case R.id.btn_back:
                    finish();
                    break;

                //道路采集
                case R.id.tv_collection_road:
                    Intent intent = new Intent(CollectionActivity.this, CollectionRoadActivity.class);
                    startActivity(intent);
                    break;

                //火场采集
                case R.id.tv_collection_fire:
                    Intent intentFire = new Intent(CollectionActivity.this, CollectionFireActivity.class);
                    startActivity(intentFire);
                    break;

                //资源采集
                case R.id.tv_collection_resource:
                    requestPermission(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA,
                            Manifest.permission.RECORD_AUDIO, Manifest.permission.MODIFY_AUDIO_SETTINGS}, 0x001);
                    break;

                //采集道路列表
                case R.id.tv_road_list:
                    if (Utils.isLoginOffLine(getApplicationContext())){
                        return;
                    }
                    type = 0;
                    Intent intentList0 = new Intent(CollectionActivity.this, CollectionListActivity.class);
                    intentList0.putExtra("type", type);
                    startActivity(intentList0);
                    break;

                //采集火场列表
                case R.id.tv_fire_list:
                    if (Utils.isLoginOffLine(getApplicationContext())){
                        return;
                    }
                    type = 1;
                    Intent intentList1 = new Intent(CollectionActivity.this, CollectionListActivity.class);
                    intentList1.putExtra("type", type);
                    startActivity(intentList1);
                    break;

                //采集资源列表
                case R.id.tv_resource_list:
                    if (Utils.isLoginOffLine(getApplicationContext())){
                        return;
                    }
                    type = 2;
                    Intent intentList2 = new Intent(CollectionActivity.this, CollectionListActivity.class);
                    intentList2.putExtra("type", type);
                    startActivity(intentList2);
                    break;

                default:
                    break;
            }
        }
    }

    @Override
    public void permissionSuccess(int requestCode) {
        if (requestCode == 0x001) {
            Intent intentResource = new Intent(CollectionActivity.this, CollectionResourceActivity.class);
            startActivity(intentResource);
        }
    }
}
